package cn.tedu.kcircle.check.admin.adapter.controller;

import cn.tedu.kcircle.check.admin.adapter.converter.CheckConverter;
import cn.tedu.kcircle.check.admin.protocol.param.CheckStateUpdateParam;
import cn.tedu.kcircle.check.admin.service.CheckAdminService;
import cn.tedu.kcircle.check.admin.service.bo.CheckStateUpdateBO;
import cn.tedu.kcircle.common.po.CurrentPrincipal;
import cn.tedu.kcircle.common.restful.JsonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
@AllArgsConstructor
@Tag(name = "审核管理")
public class CheckAdminController {
    private CheckAdminService checkAdminService;
    private CheckConverter converter;
    @PostMapping("pass")
    @Operation(summary = "审核通过")
    public JsonResult<Void> checkPass(@AuthenticationPrincipal CurrentPrincipal principal, CheckStateUpdateParam checkStateUpdateParam){
        CheckStateUpdateBO checkStateUpdateBO = converter.param2BO(checkStateUpdateParam);
        checkStateUpdateBO.setOpUserId(principal.getUserId());
        checkStateUpdateBO.setOpUsername(principal.getUsername());
        checkAdminService.checkPass(checkStateUpdateBO);
        return JsonResult.ok();
    }
    @PostMapping("reject")
    @Operation(summary = "审核驳回")
    public JsonResult<Void> checkReject(@AuthenticationPrincipal CurrentPrincipal principal, CheckStateUpdateParam checkStateUpdateParam){
        CheckStateUpdateBO checkStateUpdateBO = converter.param2BO(checkStateUpdateParam);
        checkStateUpdateBO.setOpUserId(principal.getUserId());
        checkStateUpdateBO.setOpUsername(principal.getUsername());
        checkAdminService.checkReject(checkStateUpdateBO);
        return JsonResult.ok();
    }

}
